home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Encoding:
Text File  |  2005-03-10  |  5.0 KB  |  189 lines

  1. function closeWindow(aClose)
  2. {
  3.   var windowCount = 0;
  4.    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  5.                       .getService(Components.interfaces.nsIWindowMediator);
  6.   var e = wm.getEnumerator(null);
  7.   
  8.   while (e.hasMoreElements()) {
  9.     var w = e.getNext();
  10.     if (++windowCount == 2) 
  11.       break;
  12.   }
  13.  
  14. //@line 16 "/c/mozilla/toolkit/content/globalOverlay.js"
  15.   // If we're down to the last window and someone tries to shut down, check to make sure we can!
  16.   if (windowCount == 1 && !canQuitApplication())
  17.     return false;
  18. //@line 20 "/c/mozilla/toolkit/content/globalOverlay.js"
  19.  
  20.   if (aClose)    
  21.     window.close();
  22.   
  23.   return true;
  24. }
  25.  
  26. function canQuitApplication()
  27. {
  28.   var os = Components.classes["@mozilla.org/observer-service;1"]
  29.                      .getService(Components.interfaces.nsIObserverService);
  30.   if (!os) return true;
  31.   
  32.   try {
  33.     var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  34.                               .createInstance(Components.interfaces.nsISupportsPRBool);
  35.     os.notifyObservers(cancelQuit, "quit-application-requested", null);
  36.     
  37.     // Something aborted the quit process. 
  38.     if (cancelQuit.data)
  39.       return false;
  40.   }
  41.   catch (ex) { }
  42.   os.notifyObservers(null, "quit-application-granted", null);
  43.   return true;
  44. }
  45.  
  46. function goQuitApplication()
  47. {
  48.   if (!canQuitApplication())
  49.     return false;
  50.  
  51.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  52.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  53.   var enumerator = windowManagerInterface.getEnumerator( null );
  54.   var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
  55.                      getService(Components.interfaces.nsIAppStartup);
  56.  
  57.   while ( enumerator.hasMoreElements()  )
  58.   {
  59.      var domWindow = enumerator.getNext();
  60.      if (("tryToClose" in domWindow) && !domWindow.tryToClose())
  61.        return false;
  62.      domWindow.close();
  63.   };
  64.   appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
  65.   return true;
  66. }
  67.  
  68. //
  69. // Command Updater functions
  70. //
  71. function goUpdateCommand(command)
  72. {
  73.   try {
  74.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  75.  
  76.     var enabled = false;
  77.  
  78.     if ( controller )
  79.       enabled = controller.isCommandEnabled(command);
  80.  
  81.     goSetCommandEnabled(command, enabled);
  82.   }
  83.   catch (e) {
  84.     dump("An error occurred updating the "+command+" command\n");
  85.   }
  86. }
  87.  
  88. function goDoCommand(command)
  89. {
  90.   try {
  91.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  92.     if ( controller && controller.isCommandEnabled(command))
  93.       controller.doCommand(command);
  94.   }
  95.   catch (e) {
  96.     dump("An error occurred executing the " + command + " command\n" + e + "\n");
  97.   }
  98. }
  99.  
  100.  
  101. function goSetCommandEnabled(id, enabled)
  102. {
  103.   var node = document.getElementById(id);
  104.  
  105.   if ( node )
  106.   {
  107.     if ( enabled )
  108.       node.removeAttribute("disabled");
  109.     else
  110.       node.setAttribute('disabled', 'true');
  111.   }
  112. }
  113.  
  114. function goSetMenuValue(command, labelAttribute)
  115. {
  116.   var commandNode = top.document.getElementById(command);
  117.   if ( commandNode )
  118.   {
  119.     var label = commandNode.getAttribute(labelAttribute);
  120.     if ( label )
  121.       commandNode.setAttribute('label', label);
  122.   }
  123. }
  124.  
  125. function goSetAccessKey(command, valueAttribute)
  126. {
  127.   var commandNode = top.document.getElementById(command);
  128.   if ( commandNode )
  129.   {
  130.     var value = commandNode.getAttribute(valueAttribute);
  131.     if ( value )
  132.       commandNode.setAttribute('accesskey', value);
  133.   }
  134. }
  135.  
  136. // this function is used to inform all the controllers attached to a node that an event has occurred
  137. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  138. // menu items back to their default values)
  139. function goOnEvent(node, event)
  140. {
  141.   var numControllers = node.controllers.getControllerCount();
  142.   var controller;
  143.  
  144.   for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  145.   {
  146.     controller = node.controllers.getControllerAt(controllerIndex);
  147.     if ( controller )
  148.       controller.onEvent(event);
  149.   }
  150. }
  151.  
  152. function visitLink(aEvent) {
  153.   var node = aEvent.target;
  154.   while (node.nodeType != Node.ELEMENT_NODE)
  155.     node = node.parentNode;
  156.   var url = node.getAttribute("link");
  157.   if (url != "")
  158.     top.opener.openNewWindowWith(url, null, false);
  159. }
  160.  
  161. function isValidLeftClick(aEvent, aName)
  162. {
  163.   return (aEvent.button == 0 && aEvent.originalTarget.localName == aName);
  164. }
  165.  
  166. function setTooltipText(aID, aTooltipText)
  167. {
  168.   var element = document.getElementById(aID);
  169.   if (element)
  170.     element.setAttribute("tooltiptext", aTooltipText);
  171. }
  172.  
  173. function FillInTooltip ( tipElement )
  174. {
  175.   var retVal = false;
  176.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  177.   if (textNode) {
  178.     while (textNode.hasChildNodes())
  179.       textNode.removeChild(textNode.firstChild);
  180.     var tipText = tipElement.getAttribute("tooltiptext");
  181.     if (tipText) {
  182.       var node = document.createTextNode(tipText);
  183.       textNode.appendChild(node);
  184.       retVal = true;
  185.     }
  186.   }
  187.   return retVal;
  188. }
  189.